/**
  ************************************* Copyright ******************************
  * FileName   : debug.c
  * Version    : v1.0
  * Author     : yychao
  * Date       : 2023-03-03
  * Description:
  * Function List:
  	1. ....
  	   <version>:
  <modify staff>:
  		  <data>:
   <description>:
  	2. ...
  ******************************************************************************
 */
#include "cJSON.h"
#include "log.h"
#include "debug.h"
#include "usart.h"
#include "string.h"
#include "adc_app.h"
#include "ds18b20.h"
#include "dma.h"
#include "lfs_port.h"
#include "gpio.h"
#include "soft_timer.h"
#include "rtc.h"
#include "io_ctrl.h"
/**********************************************************/



/**********************************************************/
void debug_deal(usart_cache* recv) //DataBuff* recv
{

    cJSON* json;
    cJSON* pwm_value;
    cJSON* read;
    cJSON* write;
    cJSON* value;
    uint16_t array_num;

    uint16_t pause_value = 0;

    const char* ptr = NULL;
    ptr = (const char*)&recv->data[3];
    json = cJSON_Parse(ptr);
    if (json == NULL) {
        LOG_DEBUG("json fmt error: \r\n %s\r\n", cJSON_GetErrorPtr());
        cJSON_Delete(json);
        return;
    }
//    LOG_DEBUG("json fmt ok\r\n");
	return;

    pwm_value = cJSON_GetObjectItem(json, "PWM_VALUE");
    if (pwm_value != NULL) {
        write = cJSON_GetObjectItem(pwm_value, "W");
        if (write != NULL) {
            array_num = cJSON_GetArraySize(write);
            for(int cnt = 0; cnt < array_num; cnt++) {
                value = cJSON_GetArrayItem(write, cnt);
                if(value == NULL) {
                    continue;
                }
                switch(cnt) {
                case 0:
                    LOG_DEBUG("PA11 PWM1_VALUE: %f \r\n", value->valuedouble);
                    if((value->valuedouble < 0)||(value->valuedouble > 100)) {
                        LOG_DEBUG("PA11 PWM1_VALUE Is Overflow \r\n");
                    } else {
                        //duty_cycle = PWM1_VALUE/100;
                        //duty_cycle = Pulse/Period*100%;
                        //Pulse = Period*duty_cycle;
                        //pause_value = 100*value->valuedouble/100;
                        pause_value = value->valuedouble;
                        TIM_SetCmp4(TIM1, pause_value);
                    }
                    break;
                case 1:
                    LOG_DEBUG("PB14 PWM2_VALUE: %f \r\n", value->valuedouble);
                    if((value->valuedouble < 0)||(value->valuedouble > 100)) {
                        LOG_DEBUG("PB14 PWM2_VALUE Is Overflow \r\n");
                    } else {
                        pause_value = value->valuedouble;
                        TIM_SetCmp2(TIM1, pause_value);
                    }
                    break;
                }
            }
        }
    }
    cJSON_Delete(json);



}

